﻿using System;
namespace Xtee.XteeClient.Metadata {
    using global::Metadata.Xroad.Eu;
    using global::Metadata.Xroad.Eu.Messages;
    using global::Xtee.Core;
    using System.Collections.Generic;
    
    
    public class MetadataAdapter {
        
        private string _protocolVersion = "4.0";
        
        private Xtee.Core.Client.IXteeCommand _xteeCommand;
        
        public MetadataAdapter() : 
                this(new Xtee.Core.Client.XteeCommand(new Xtee.Core.Client.Config.Configuration())) {
        }
        
        public MetadataAdapter(Xtee.Core.Client.IXteeCommand command) {
            this._xteeCommand = command;
        }
        
        public virtual Xroad.Eu.Xsd.Identifiers.XRoadServiceIdentifierType Service {
            get {
                return new Xroad.Eu.Xsd.Identifiers.XRoadServiceIdentifierType(){ObjectType = "", XRoadInstance = "",MemberClass = "", MemberCode = "", SubsystemCode = ""};
            }
        }
        
        public virtual string ProtocolVersion {
            get {
                return this._protocolVersion;
            }
            set {
                this._protocolVersion = value;
            }
        }
        
        public virtual Xtee.Core.Client.IXteeCommand XteeCommand {
            get {
                return this._xteeCommand;
            }
            set {
                this._xteeCommand = value;
            }
        }
        
        public virtual global::Metadata.Xroad.Eu.Messages.AllowedMethodsResponse AllowedMethods() {
            var allowedMethodsInputHeader = new global::Metadata.Xroad.Eu.Headers.AllowedMethodsInputHeader();
            allowedMethodsInputHeader.Client = _xteeCommand.Configuration.Client;
            allowedMethodsInputHeader.Id = Xtee.Core.Utils.StringUtils.GenerateNonce();
            allowedMethodsInputHeader.ProtocolVersion = this.ProtocolVersion;
            allowedMethodsInputHeader.Service = Service;
            allowedMethodsInputHeader.Service.ServiceCode = "allowedMethods";
            allowedMethodsInputHeader.Service.ServiceVersion = null;
            allowedMethodsInputHeader.UserId = _xteeCommand.Configuration.UserId;
            global::Xtee.Core.Envelope.ISoapEnvelope responseEnvelope = _xteeCommand.Execute(new global::Xtee.Core.Envelope.SoapEnvelope(new System.Xml.XmlQualifiedName("meta", "http://metadata.x-road.eu/"), new System.Collections.Generic.List<System.Xml.XmlQualifiedName>{new System.Xml.XmlQualifiedName("id", "http://x-road.eu/xsd/identifiers")}, "allowedMethods", allowedMethodsInputHeader, new global::Metadata.Xroad.Eu.Messages.AllowedMethods()));
            return ((global::Metadata.Xroad.Eu.Messages.AllowedMethodsResponse)(responseEnvelope.Body));
        }
        
        public virtual global::Metadata.Xroad.Eu.Messages.ListMethodsResponse ListMethods() {
            var listMethodsInputHeader = new global::Metadata.Xroad.Eu.Headers.ListMethodsInputHeader();
            listMethodsInputHeader.Client = _xteeCommand.Configuration.Client;
            listMethodsInputHeader.Id = Xtee.Core.Utils.StringUtils.GenerateNonce();
            listMethodsInputHeader.ProtocolVersion = this.ProtocolVersion;
            listMethodsInputHeader.Service = Service;
            listMethodsInputHeader.Service.ServiceCode = "listMethods";
            listMethodsInputHeader.Service.ServiceVersion = null;
            listMethodsInputHeader.UserId = _xteeCommand.Configuration.UserId;
            global::Xtee.Core.Envelope.ISoapEnvelope responseEnvelope = _xteeCommand.Execute(new global::Xtee.Core.Envelope.SoapEnvelope(new System.Xml.XmlQualifiedName("meta", "http://metadata.x-road.eu/"), new System.Collections.Generic.List<System.Xml.XmlQualifiedName>{new System.Xml.XmlQualifiedName("id", "http://x-road.eu/xsd/identifiers")}, "listMethods", listMethodsInputHeader, new global::Metadata.Xroad.Eu.Messages.ListMethods()));
            return ((global::Metadata.Xroad.Eu.Messages.ListMethodsResponse)(responseEnvelope.Body));
        }
    }
}
